import { Injectable, EventEmitter } from '@angular/core';
import { Subject, Observable } from 'rxjs';

export const MSG_TYPE = {
  /**
   * 更新账号基本信息
   */
  MODIFY_USERINFO: 'modify_userinfo',
};

export interface AppMsg {
  type: string;
  data?: any;
}

@Injectable({ providedIn: 'root' })
export class EmitterService {
  private subject = new Subject<any>();

  isLoaded = false;

  sendMessage(appMsg: AppMsg) {
    this.subject.next(appMsg);
  }

  clearMessage() {
    this.subject.next();
  }

  getMessage(): Observable<AppMsg> {
    return this.subject.asObservable();
  }
}
